#include "MySQL.h"
#include "MyGUI.h"

#define EXAMPLE_QUERY_1 "SELECT products, no, price, flag FROM test"
#define EXAMPLE_QUERY_2 "SELECT product FROM products ORDER BY product ASC"

// Connection properties
#define EXAMPLE_DB   "test"
#define EXAMPLE_HOST "tcp://127.0.0.1:3306"
#define EXAMPLE_USER "root"
#define EXAMPLE_PASS "admin"

Driver *driver;
Connection *con;

int main(int argc, char *argv[])
{
	string url;
	string user;
	string pass;
	string database;

	if (argc >= 2) url=argv[1]; else url=EXAMPLE_HOST;
	if (argc >= 3) user=argv[2]; else user=EXAMPLE_USER;
	if (argc >= 4) pass=argv[3]; else pass=EXAMPLE_PASS;
	if (argc >= 5) database=argv[4]; else database=EXAMPLE_DB;

	driver = get_driver_instance();
	/* Using the Driver to create a connection */
	con = driver->connect(url, user, pass);
	con->setSchema(database);
	/* Creating a "simple" statement - "simple" = not a prepared statement */
	stmt = con->createStatement();

    gtk_init (&argc, &argv);

      GtkWidget *bar;
      GtkWidget *label;

      entry1 = gtk_entry_new ();
      gtk_entry_set_text (GTK_ENTRY (entry1), EXAMPLE_QUERY_1);
      entry2 = gtk_entry_new ();
      gtk_entry_set_text (GTK_ENTRY (entry2), EXAMPLE_QUERY_2);

      /* create window, etc */
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_title (GTK_WINDOW (window), "MySQLBrowser");
      gtk_container_set_border_width (GTK_CONTAINER (window), 5);
      g_signal_connect (window, "destroy",
                        G_CALLBACK (gtk_widget_destroyed), &window);

      vbox = gtk_vbox_new (FALSE, 5);

      My_GUI::add_menu();

      bar = gtk_info_bar_new ();
      gtk_box_pack_start (GTK_BOX (vbox), bar, FALSE, FALSE, 0);
      gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_WARNING);
      label = gtk_label_new ("You may edit the cells below!");
      gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))), label, FALSE, FALSE, 0);

      sw = gtk_scrolled_window_new (NULL, NULL);

      gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
                                           GTK_SHADOW_ETCHED_IN);
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                      GTK_POLICY_AUTOMATIC,
                                      GTK_POLICY_AUTOMATIC);
      gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);

      gtk_container_add (GTK_CONTAINER (window), vbox);

      gtk_window_set_default_size (GTK_WINDOW (window), 320, 200);

  if (!gtk_widget_get_visible (window))
    gtk_widget_show_all (window);
  else
    {
      gtk_widget_destroy (window);
      window = NULL;
    }

	gtk_main();
	return 0;
}
